<?php
/*//=================================================方法工厂模式==========================================================
interface  InterfaceLog{
public function  log();
}
class MysqlLog implements InterfaceLog {

    public function log()
    {
        // TODO: Implement log() method.
    }
}
class RedisLog implements InterfaceLog {

    public function log()
    {
        // TODO: Implement log() method.
    }
}
class UserLog implements  InterfaceLog {


    public function log()
    {
        // TODO: Implement log() method.
    }
}
class  Log{
    protected $log;
    public function __construct()
    {
      $this->log=array(
          (new MysqlFactory())->make(),
          (new RedisFactory())->make(),
          (new UserFactory())->make(),
      );
    }
    public function  getLog(){
        return $this->log;
    }

}
interface LogFactoryInterface{
    public  function  make();
}
class MysqlFactory implements  LogFactoryInterface {
    public function make()
    {
        return new MysqlLog();
    }
}
class RedisFactory implements  LogFactoryInterface{

    public function make()
    {
       return new RedisLog();
    }
}
class UserFactory implements  LogFactoryInterface{

    public function make()
    {
        return new UserLog();
    }
}
$log= new  Log();
var_dump($log->getLog());*/
/*//=================================================抽象工厂模式==========================================================
interface PayInterface{
public function  pay();
}
class AliPay implements  PayInterface{

    public function pay()
    {
        return "这是alipay支付";
    }
}
class WeachatPay implements PayInterface{
    public function pay()
    {
        return "这是wechat支付";
    }
}
interface  InterfaceLog{
    public function  log();
}
class MysqlLog implements InterfaceLog {

    public function log()
    {
        return "mysql 日志";
    }
}
class RedisLog implements InterfaceLog {

    public function log()
    {
        return "redis 日志";
    }
}
interface  PayFactoryInterface {
    public  function AliPayMake();
    public  function WechatPayMake();
}

class PayFactory implements PayFactoryInterface {

    public function AliPayMake()
    {
        return new AliPay();
    }

    public function WechatPayMake()
    {
        return new WeachatPay();
    }
}
interface LogFactoryInterFace{
    public  function  MysqlLogMake();
    public  function  RedisLogMake();
}
class LogFactory implements  LogFactoryInterFace{

    public function MysqlLogMake()
    {
       return new MysqlLog();
    }

    public function RedisLogMake()
    {
       return new  RedisLog();
    }
}
class  Log {
    protected $log;
    protected  $pay;
    public  function __construct()
    {
        $PayFactory= new PayFactory();
        $LogFactory = new LogFactory();
        $this->log=array(
            $LogFactory->RedisLogMake(),
            $LogFactory->MysqlLogMake(),
        );
        $this->pay=array(
            $PayFactory->AliPayMake(),
            $PayFactory->WechatPayMake(),
        );
    }
        public function getLog(){
        return $this->log;

    }
    public  function getPay(){
        return $this->pay;
    }
}
$log = new Log();
var_dump($log->getLog());
var_dump($log->getPay());*/
//=================================================单例模式==========================================================
class  Request{
    /**
     * @var 接收本类的对象
     */
    private static $request;
    /**
     * @var 请求的方法
     */
    protected $method;
    /**
     * @var 请求的地址
     */
    protected $uriPath;
    #三私一公
    private  function __construct()
    {
    }
    private function __clone()
    {
        // TODO: Implement __clone() method.
    }
    public static function getRequest(){
       if(self::$request==null){
           self::$request= new Request();
       }
       self::$request->method=$_SERVER["REQUEST_METHOD"];
       self::$request->uriPath=$_SERVER["REQUEST_URI"];
                return self::$request;
    }

    /**
     * @return 请求的方法
     */
    public function  getMethod(){
        return $this->method;
    }

    /**
     * @return 请求的地址
     */
    public  function getUriPath(){
        return $this->uriPath;
    }

    /**
     * @param $method
     * @return bool
     * 判断请求的方法
     */
    public function  isMethod($method):bool
    {
        #strtoupper 不区分大小写
        return  $this->method===strtoupper($method);
    }
}
$request= Request::getRequest();
var_dump($request->isMethod("get"));